<template>
  <div class="box">
    <div class="recommend_pro">
      <div class="recommend">相关推荐</div>
      <div v-if="proDetailData.length === 2" class="main">
        <div :v-if="proDetailData.length" class="main_pro" v-for="(item, index) in proDetailData" :key="index" @click="toProDetail(item.proid)">
          <img :src="item.pro_pic" alt="">
          <p>{{item.pro_introduce}}</p>
          <span class="clinic_name">{{'【' + item.pro_city + '】' + item.clinic_name}}</span>
          <div>
            <span>￥<b>{{item.pro_price}}</b></span>
            <span>{{item.subscribe + '已预约'}}</span>
          </div>
        </div>
      </div>
      <div v-else class="refresh" @click="refresh">点击空白地方重新加载</div>
    </div>
  </div>
</template>

<script>
import { getProductById } from '../../api'
export default {
  data () {
    return {
      recommend_proid1: `1000${Math.floor(Math.random() * 80 + 10)}`,
      recommend_proid2: `1000${Math.floor(Math.random() * 80 + 10)}`,
      proDetailData: []
    }
  },
  mounted () {
    this.getProductPro()
  },
  methods: {
    toProDetail (proid) {
      this.$router.replace({ path: '/proDetail', query: { proid } })
      this.$router.go(0)
    },
    getProductPro () {
      getProductById({
        proid: this.recommend_proid1,
        username: localStorage.getItem('userTel_AM') ? localStorage.getItem('userTel_AM') : '11000000000'
      }).then(res => {
        const proDetailData = []
        proDetailData.push(res.data.data[0])
        getProductById({
          proid: this.recommend_proid2,
          username: localStorage.getItem('userTel_AM') ? localStorage.getItem('userTel_AM') : '11000000000'
        }).then(res => {
          proDetailData.push(res.data.data[0])
        })
        this.proDetailData = proDetailData
      })
    },
    refresh () {
      this.getProductPro()
    }
  }
}
</script>

<style lang="scss" scoped>
.refresh {
  width: 100%;
  height: 1rem;
  margin: 0.15rem 0 0.5rem 0;
  line-height: 1rem;
  text-align: center;
  color: #999999;
}
.recommend_pro {
  width: 100%;
  height: auto;
  padding: 0 0.15rem;
  .recommend {
    margin-top: 0.2rem;
    width: 100%;
    height: 0.5rem;
    background:rgba(244,244,244,1);
    box-shadow:0rem 0.06rem 0.1rem 0rem rgba(97,97,97,0.2);
    font-size: 0.16rem;
    line-height: 0.5rem;
    color: #666666;
    font-weight: bold;
    text-align: center;
    border-radius: 0.05rem;
  }
  .main {
    width: 100%;
    height: auto;
    display: flex;
    margin-bottom: 0.5rem;
    justify-content: space-between;
    margin-top: 0.15rem;
    .main_pro {
      width: 49%;
      height: auto;
      background:rgba(244,244,244,1);
      border-radius: 0.05rem;
      img {
        width: 100%;
      }
      p {
        width: 100%;
        height: 0.4rem;
        line-height: 0.2rem;
        font-size: 0.14rem;
        color: #464646;
        padding: 0 0.05rem;
        margin-top: 0.08rem;
        text-overflow: -o-ellipsis-lastline;
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
      }
      .clinic_name {
        display: block;
        line-height: 0.12rem;
        width: 100%;
        height: 0.12rem;
        font-size: 0.12rem;
        color: #666666;
        margin-top: 0.08rem;
        padding: 0 0.05rem;
        overflow: hidden;
        text-overflow:ellipsis;
        white-space: nowrap;
      }
      div {
        width: 100%;
        height: 0.16rem;
        margin-top: 0.08rem;
        padding: 0 0.05rem;
        margin-bottom: 0.08rem;
        span:nth-of-type(1) {
          float: left;
          font-size: 0.12rem;
          line-height: 0.16rem;
          color: #FF5959;
          b {
            font-size: 0.16rem;
          }
        }
        span:nth-of-type(2) {
          float: right;
          color: #999999;
          font-size: 0.12rem;
          line-height: 0.16rem;
        }
      }
    }
  }
}
</style>
